import 'package:flutter/material.dart';
import 'package:xunlongchi/util/app_util.dart';
import 'package:xunlongchi/util/data_util.dart';
import 'package:xunlongchi/widgets/animated_scale.dart';

///时辰
class Shichen extends StatefulWidget {
  const Shichen({Key key}) : super(key: key);

  @override
  _ShichenState createState() => _ShichenState();
}

class _ShichenState extends State<Shichen> {
  bool _ready = false;

  @override
  void initState() {
    super.initState();

    () async {
      await Future.delayed(const Duration(milliseconds: 1100), () {
        setState(() {
          _ready = true;
        });
      });
    }();
  }

  @override
  Widget build(BuildContext context) {
    return AnimatedOpacity(
      opacity: _ready ? 1 : 0,
      duration: const Duration(milliseconds: 500),
      child: AnimatedScale(
        scale: _ready ? 1 : 1.2,
        duration: const Duration(milliseconds: 500),
        child: const ShichenBody(),
      ),
    );
  }
}

class ShichenBody extends StatelessWidget {
  const ShichenBody({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final List<Widget> _item = Iterable<int>.generate(6)
        .map((i) => RotationTransition(
              turns: AlwaysStoppedAnimation(-30 * i / 360 - 90 / 360),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  RotatedBox(
                    quarterTurns: -1,
                    child: Text('${DataUtil.sc[i + 6]}'),
                  ),
                  RotatedBox(
                    quarterTurns: 1,
                    child: Text('${DataUtil.sc[i]}'),
                  ),
                ],
              ),
            ))
        .toList();

    final double _shichenSize = 780.px;

    return DefaultTextStyle(
      style: TextStyle(
        color: Colors.amber,
        fontSize: 40.sp,
        fontWeight: FontWeight.bold,
      ),
      child: SizedBox(
        width: _shichenSize,
        height: _shichenSize,
        child: Stack(
          alignment: Alignment.center,
          children: _item,
        ),
      ),
    );
  }
}
